import { defineSource } from '../source';
import { ProcessedItem } from '../types'
import { myFetch } from "../utils/fetch"
import logger from '../../framework/config/logger';

interface Res {
    data: {
        hotNews: {
            contId: string
            name: string
            pubTimeLong: string
            praiseTimes: string
        }[]
    }
}

export default defineSource({
    thepaper: async (): Promise<ProcessedItem[]> => {
        const url = "https://cache.thepaper.cn/contentapi/wwwIndex/rightSidebar"
        const res: Res = await myFetch(url)
        return res.data.hotNews
            .map((k) => {
                return {
                    id: k.contId,
                    title: k.name,
                    url: `https://www.thepaper.cn/newsDetail_forward_${k.contId}`,
                    mobileUrl: `https://m.thepaper.cn/newsDetail_forward_${k.contId}`,
                    extra: {
                        hot: k.praiseTimes,
                    },
                }
            })
    }
});